package com.woniu.map.controller;

import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.response.TerminalResponse;
import com.woniu.map.service.TerminalService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/terminal")
public class TerminalController {

    @Resource
    private TerminalService terminalService;

    /**
     * 添加终端
     * @param name 车牌号
     * @param desc  车id
     * @return
     */

    @GetMapping("/add")
    public ResponseResult<TerminalResponse> addTerminal(@RequestParam("name") String name ,
                                                        @RequestParam("desc") String desc){

        return terminalService.addTerminal(name,desc);
    }

    /**
     * 查附近车辆
     * @param center 纬度,经度
     * @param radius 半径 小于15000
     * @return
     */
    @GetMapping( "/aroundSearch")
    public ResponseResult<TerminalResponse> aroundSearch(@RequestParam("center") String center,
                                                         @RequestParam("radius") Integer radius){
        if (radius > 8000)
            return ResponseResult.fail("半径不能大于15000");

        return terminalService.aroundSearch(center,radius);
    }

}
